<template>
	<view>
		<view class="fjb">
			<view class="tac">
			  <input :value="value[0]" placeholder="开始日期" @click="index=0;show=true" disabled input-align="center" class="f1" />
			</view>
			<span class="c9">至</span>
			<view class="tac">
			  <input :value="value[1]" placeholder="结束日期" @click="index=1;show=true" disabled input-align="center" class="f1" />
			</view>
			<text v-if="value && value[1] !== '长期'" @click="longtime" class="h5 fac br2 px2 tsn fs22 fc-primary ol-primary">长期</text>
		</view>
		<u-picker v-model:show="show" mode="time" :default-time="value[index]!='长期'?value[index]:''" end-year="2200" @confirm="confirm" confirm-color="#00b280" :params="params" />
	</view>
</template>

<script>
import util from '@/utils/util'
import Emitter from 'uview-plus/libs/util/emitter'

export default {
	mixins: [Emitter],
	props: {
		value: {
			type: Array,
			default: () => []
		},
		params: {
			type: Object,
			default: () => ({
				year: true,
				month: true,
				day: true,
				hour: false,
				minute: false,
				second: false,
				timestamp: true
			})
		}
	},
	data() {
		return {
			show: false,
			index: 0
		}
	},
	methods: {
		confirm(e){
			this.value[this.index] = e.year + '-' + e.month + '-' + e.day
			this.$emit('update:value', this.value)
			setTimeout(() => {
				this.dispatch('u-form-item', 'onFieldChange', this.value)
			}, 40)
		},
		longtime(){
			this.value[1] = '长期'
			this.$emit('update:value', this.value)
			this.$forceUpdate()
			setTimeout(() => {
				this.dispatch('u-form-item', 'onFieldChange', this.value)
			}, 40)
		}
	}
}
</script>
